#!/bin/sh

set -e


echo "监控器启动成功"

while true
do
    if `printf "GET / HTTP/1.0\n\n" | nc -w 2 $INSIDEHTTP_PORT_8080_TCP_ADDR $INSIDEHTTP_PORT_8080_TCP_PORT | grep -q '200 OK'`
    then
        date=`date`
        printf "[%s] 系统运行中.\n" "$date"
    else 
        date=`date`
        printf "[%s] 系统异常，发送告警邮件!\n" "$date"
        printf "[%s] To: admin@work  Message: 服务停止运行，请检修!" "$date" | nc $INSIDEMAILER_PORT_50000_TCP_ADDR $INSIDEMAILER_PORT_50000_TCP_PORT
        break
    fi

    sleep 1
done